#!/bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始全量导入==============='
echo '========================================'

# ========== 全量 ==========

# 1. 班级在读人数表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select id, school_id, subject_id, class_id, ifnull(studying_student_count,0) studying_student_count, studying_date, '${TD_DATE}' as dt from class_studying_student_count where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table class_studying_student_count \
-m 100 \
--split-by id
wait

# 2. 班级课表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from course_table_upload_detail where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table course_table_upload_detail \
-m 100 \
--split-by id
wait

# 3. 班级作息时间表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from tbh_class_time_table where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table tbh_class_time_table \
-m 100 \
--split-by id
wait

# 4. 学生打卡记录表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from tbh_student_signin_record where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table tbh_student_signin_record \
-m 100 \
--split-by id
wait

# 5. 学生请假申请表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from student_leave_apply where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table student_leave_apply \
-m 100 \
--split-by id
wait

# 6. 日历 表
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/teach \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from calendar where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table calendar \
-m 100 \
--split-by id
wait

echo '========================================'
echo '=================success==============='
echo '========================================'
